home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / Mod-Player.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  40KB  |  1,693 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATUtilities HiFi-Player                   ** */
  4. /* **            Copright (C) 1993-1994 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* ******************************************************************* */
  8.  
  9. #include "ATUtilities.h"
  10. #include "HiFi.h"
  11.  
  12. UBYTE *HelpName="AT:Help/HiFiPlayer.help";
  13.  
  14. #define MAXTITLES 250
  15. #define CATSIZE ((4+(MAXTITLES*128))          + 20000L)
  16. #define CATFILESIZE(x) (4+(x*128))
  17.  
  18. UBYTE PlayCount[MAXTITLES];
  19.  
  20.  
  21.  
  22. UBYTE anti_error1[4096];
  23.  
  24.  
  25. struct Catalog
  26. {
  27.  UWORD Entries;
  28.  UBYTE Random;
  29.  UBYTE Pad;
  30.  UBYTE Title[1][128];
  31. } *Catalog,*Cat2;
  32.  
  33. struct Interrupt MyInt;
  34.  
  35.  
  36.  
  37.  
  38. UBYTE anti_error2[1000];
  39.  
  40.  
  41.  
  42. struct Library   *GfxBase;
  43. struct Library   *IntuitionBase;
  44. struct Library   *ATUtilitiesBase;
  45. struct Library   *AslBase;
  46. struct Library   *UtilityBase;
  47. struct Library   *GadToolsBase;
  48. extern struct Library *SysBase;
  49. extern struct Library *DOSBase;
  50.  
  51. struct Task     *Task;
  52. struct TextFont *opal;
  53. struct Window   *HCWindow;
  54. struct Screen   *HCScreen;
  55. struct RastPort *HCRPort;
  56. struct ViewPort *HCViewPort;
  57.  
  58. struct TagItem       *ReqTags;
  59. struct FileRequester *FileReq;
  60. struct WBArg         *fargs;
  61. struct Lock          *lock;
  62. UBYTE                 dir[130];
  63.  
  64. struct NewScreen HCScreenDef=
  65. {
  66.  0,210,640,45,2,
  67.  0,1,HIRES,CUSTOMSCREEN,
  68.  0,0,0,0
  69. };
  70.  
  71. struct NewWindow HCWindowDef=
  72. {
  73.  0,0,640,45,0,1,
  74.  0L,BORDERLESS,
  75.  0L,0L,0L,0L,0L,
  76.  50,50,640,100,
  77.  CUSTOMSCREEN
  78. };
  79.  
  80. LONG  PortSignal;
  81. ULONG PortSignalMask;
  82. ULONG WaitSignalMask;
  83. ULONG Signale;
  84.  
  85. VOID Update();
  86. VOID HiFiControl();
  87. VOID StopSymbol();
  88. VOID WaitSymbol();
  89. VOID PlaySymbol();
  90. VOID ShowPlayer();
  91. VOID ShowSTitle();
  92. VOID ShowVolume();
  93. VOID ShowInfo();
  94. VOID OpenAll();
  95. VOID CloseAll();
  96. VOID TitleEd();
  97. VOID LoadCatalog();
  98. VOID SaveCatalog();
  99. BOOL CheckX();
  100. BOOL AuPrefs();
  101.  
  102. UWORD rand();
  103. UWORD RT();
  104. UWORD Zufall();
  105. VOID  RndStart();
  106.  
  107. struct MsgPort  *Port;
  108.  
  109. struct Global
  110. {
  111.  APTR AslBase;
  112.  APTR DOSBase;
  113.  APTR IntuitionBase;
  114.  APTR GfxBase;
  115.  APTR GadToolsBase;
  116.  APTR ReservedLibraryBase;
  117.  APTR DirArrayPtr;
  118.  APTR FileArrayPtr;
  119.  APTR PathArrayPtr;
  120.  APTR  ChkData;
  121.  ULONG ChkSize;
  122.  UWORD SndNum;
  123.  UWORD SndVol;
  124.  UWORD SndLBal;
  125.  UWORD SndRBal;
  126.  UWORD LED;
  127.  UWORD Timer;
  128.  VOID (* GetListData)();
  129.  VOID (* LoadFile)();
  130.  VOID (* CopyDir)();
  131.  VOID (* CopyFile)();
  132.  VOID (* CopyString)();
  133.  VOID (* AudioAlloc)();
  134.  VOID (* AudioFree)();
  135.  
  136.  VOID (* StartInt)();
  137.  VOID (* StopInt)();
  138.  VOID (* SongEnd)();
  139.  VOID (* CutSuffix)();
  140.  VOID (* SetTimer)();
  141.  
  142.  APTR R1,R2,R3;
  143. } Global;
  144.  
  145.  
  146.  
  147.  
  148. UBYTE anti_error3[4096];
  149.  
  150.  
  151.  
  152. struct DOSSegment
  153. {
  154.  BPTR  NextSegment;
  155.  ULONG RTS;
  156.  UBYTE ID[8];
  157.  APTR  TagArray;
  158. };
  159. struct Tag
  160. {
  161.  ULONG Code;
  162.  ULONG Data;
  163. } *Tags;
  164.  
  165. struct DOSSegment *Segmente[200];
  166. BPTR               Player[200];
  167. UWORD              PlayerCnt;
  168.  
  169.  
  170.  
  171.  
  172. UBYTE anti_error4[1000];
  173.  
  174.  
  175.  
  176.  
  177. #define TAG_USER    0x80000000
  178. #define TAG_DONE    0
  179. #define TAG_IGNORE  1
  180. #define DPT_TagBase (ULONG)((ULONG)TAG_USER+(ULONG)((UWORD)'DT'))
  181.  
  182. #define DPT_InternalPlayer    DPT_TagBase+0
  183. #define DPT_CustomPlayer      DPT_TagBase+1
  184. #define DPT_RequestDTVersion  DPT_TagBase+2
  185. #define DPT_RequestV37        DPT_TagBase+3
  186. #define DPT_PlayerVersion     DPT_TagBase+4
  187. #define DPT_PlayerName        DPT_TagBase+5
  188. #define DPT_Creator           DPT_TagBase+6
  189. #define DPT_Check1            DPT_TagBase+7
  190. #define DPT_Check2            DPT_TagBase+8
  191. #define DPT_ExtLoad           DPT_TagBase+9
  192. #define DPT_Interrupt         DPT_TagBase+10
  193. #define DPT_Stop              DPT_TagBase+11
  194. #define DPT_Config            DPT_TagBase+12
  195. #define DPT_UserConfig        DPT_TagBase+13
  196. #define DPT_SubSoundRange     DPT_TagBase+14
  197. #define DPT_InitPlayer        DPT_TagBase+15
  198. #define DPT_EndPlayer         DPT_TagBase+16
  199. #define DPT_InitSound         DPT_TagBase+17
  200. #define DPT_EndSound          DPT_TagBase+18
  201. #define DPT_StartInt          DPT_TagBase+19
  202. #define DPT_StopInt           DPT_TagBase+20
  203. #define DPT_Volume            DPT_TagBase+21
  204. #define DPT_Balance           DPT_TagBase+22
  205. #define DPT_Faster            DPT_TagBase+23
  206. #define DPT_Slower            DPT_TagBase+24
  207. #define DPT_NextPatt          DPT_TagBase+25
  208. #define DPT_PrevPatt          DPT_TagBase+26
  209. #define DPT_NextSong          DPT_TagBase+27
  210. #define DPT_PrevSong          DPT_TagBase+28
  211. #define DPT_SubSongTest       DPT_TagBase+29
  212.  
  213. WORD CallCheck1(),CallCheck2();
  214.  
  215. VOID xGetListData();
  216. VOID xLoadFile();
  217. VOID xCopyDir();
  218. VOID xCopyFile();
  219. VOID xCopyString();
  220. VOID xAudioAlloc();
  221. VOID xAudioFree();
  222. VOID xStartInt();
  223. VOID xStopInt();
  224. VOID xSongEnd();
  225. VOID xCutSuffix();
  226. VOID xSetTimer();
  227.  
  228. APTR InitPlayer;
  229. APTR EndPlayer;
  230. APTR InitSound;
  231. APTR EndSound;
  232. APTR Interrupt;
  233. APTR StartInt;
  234. APTR StopInt;
  235. APTR Check1;
  236. APTR Check2;
  237. APTR Volume;
  238.  
  239. UBYTE *mem;
  240. UBYTE *pname;
  241. ULONG  size;
  242. UWORD  current;
  243. BOOL   play;
  244. BOOL   ploaded;
  245.  
  246. UBYTE  CurrentVol;
  247. UBYTE  pad001;
  248.  
  249.  
  250. BOOL Start();
  251. VOID Stop();
  252. VOID LoadAllPlayers();
  253. BOOL LoadPlayer();
  254. VOID UnLoadPlayers();
  255.  
  256.  
  257. /* Installationsroutine */
  258. VOID main()
  259. {
  260.  register struct Message *msg;
  261.  REGISTER LONG            i,j,k,l;
  262.  REGISTER BOOL            bool;
  263.  
  264.  ploaded=FALSE;
  265.  OpenAll();
  266.  bool=FALSE;
  267.  play=FALSE;
  268.  if(Catalog->Random==0)
  269.    current=0;
  270.  else
  271.    current=Zufall(Catalog->Entries-1);
  272.  if(HiFiPrefs.Control!=0) HiFiControl();
  273.  while(bool==FALSE)
  274.   {
  275.    Signale=Wait(WaitSignalMask);
  276.    if(Signale & PortSignalMask)
  277.     {
  278.      i=Received(Port);
  279.      while(i!=0)
  280.       {
  281.        switch(i)
  282.         {
  283.          case UTILITY_QUIT:
  284.            DisplayBeep(NULL);
  285.            if(HCScreen!=NULL) HiFiControl();
  286.            bool=TRUE;
  287.           break;
  288.          case UTILITY_HELP:
  289.            Help(HelpName,0);
  290.           break;
  291.          case UTILITY_INFO:
  292.            Stop();
  293.            ShowInfo();
  294.           break;
  295.          case 1100:
  296.            if(play==FALSE)
  297.             {
  298.              current=0;
  299.              play=Start(current);
  300.              if(play==FALSE) Stop();
  301.             }
  302.           break;
  303.          case 1001:
  304.            if(play==FALSE)
  305.             {
  306.              play=Start(current);
  307.              if(play==FALSE) Stop();
  308.             }
  309.            RndStart();
  310.           break;
  311.          case 1002:
  312.            Stop();
  313.            RndStart();
  314.            play=FALSE;
  315.           break;
  316.          case 1003:
  317.            Stop();
  318.            current=0;
  319.            play=Start(0);
  320.            if(play==FALSE) Stop();
  321.           break;
  322.          case 1004:
  323.            if(Catalog->Entries>0)
  324.             {
  325.              Stop();
  326.              current=Catalog->Entries-1;
  327.              play=Start(current);
  328.              if(play==FALSE) Stop();
  329.             }
  330.           break;
  331.          case 1005:
  332.            if(current<MAXTITLES)
  333.             {
  334.              Stop();
  335.              current=current+1;
  336.              if(current==Catalog->Entries) current=0;
  337.              play=Start(current);
  338.              if(play==FALSE) Stop();
  339.             }
  340.           break;
  341.          case 1505:
  342.            Stop();
  343.            msg=GetMsg(Port);
  344.            while(msg!=NULL)
  345.             {
  346.              ReplyMsg(msg);
  347.              msg=GetMsg(Port);
  348.             }
  349.            if(Catalog->Entries>0)
  350.             {
  351.              if(Catalog->Random!=0)
  352.               {
  353.                current=(UBYTE)Zufall(Catalog->Entries-1);
  354.                if(PlayCount[current]==1)
  355.                 {
  356.                  k=0; j=current;
  357.                  for(i=0;i<Catalog->Entries;i++)
  358.                   {
  359.                    if(PlayCount[j]==0)
  360.                     {
  361.                      k=1;
  362.                      current=j;
  363.                      break;
  364.                     }
  365.                    j++;
  366.                    if(j>=Catalog->Entries) j=0;
  367.                   }
  368.                  if(k==0)
  369.                   {
  370.                    for(i=0;i<MAXTITLES;i++)
  371.                      PlayCount[i]=0;
  372.                   }
  373.                 }
  374.               }
  375.              else
  376.               {
  377.                current=current+1;
  378.                if(current>=Catalog->Entries) current=0;
  379.               }
  380.              play=Start(current);
  381.              if(play==FALSE) Stop();
  382.             }
  383.           break;
  384.          case 1006:
  385.            if(Catalog->Entries>0)
  386.             {
  387.              Stop();
  388.              if(current>0) current=current-1; else current=Catalog->Entries-1;
  389.              play=Start(current);
  390.              if(play==FALSE) Stop();
  391.             }
  392.           break;
  393.          case 1500:
  394.            if(Catalog->Entries>0)
  395.             {
  396.              Stop();
  397.              current=(UBYTE)Zufall(Catalog->Entries-1);
  398.              if(PlayCount[current]==1)
  399.               {
  400.                k=0; j=current;
  401.                for(i=0;i<Catalog->Entries;i++)
  402.                 {
  403.                  if(PlayCount[j]==0)
  404.                   {
  405.                    k=1;
  406.                    current=j;
  407.                    break;
  408.                   }
  409.                  j++;
  410.                  if(j>=Catalog->Entries) j=0;
  411.                 }
  412.                if(k==0)
  413.                 {
  414.                  for(i=0;i<MAXTITLES;i++)
  415.                    PlayCount[i]=0;
  416.                 }
  417.               }
  418.              play=Start(current);
  419.              if(play==FALSE) Stop();
  420.             }
  421.           break;
  422.          case 1007:
  423.            if(play) Stop();
  424.            TitleEd();
  425.            play=FALSE;
  426.            current=0;
  427.            Update();
  428.           break;
  429.          case 1008:
  430.            if(play) Stop();
  431.            LoadCatalog(NULL);
  432.            if(Catalog->Random==0)
  433.              current=0;
  434.            else
  435.              current=Zufall(Catalog->Entries-1);
  436.            if(play==TRUE)
  437.             {
  438.              play=Start(current);
  439.             }
  440.            Update();
  441.           break;
  442.          case 1009:
  443.            if(play) Stop();
  444.            SaveCatalog();
  445.            if(play)
  446.             {
  447.              play=Start(current);
  448.              if(play==FALSE) Stop();
  449.             }
  450.            Update();
  451.           break;
  452.          case UTILITY_CALL:
  453.          case 1010:
  454.            if(play) Stop();
  455.            bool=AuPrefs();
  456.            if(play)
  457.             {
  458.              play=Start(current);
  459.              if(play==FALSE) Stop();
  460.             }
  461.            Update();
  462.           break;
  463.          case 1012:
  464.            HiFiControl();
  465.           break;
  466.          case 1013:
  467.            if(CurrentVol<=62) CurrentVol+=2;
  468.            Global.SndVol=CurrentVol;
  469.            if((play)&&(Volume))
  470.              CallVolume();
  471.            ShowVolume();
  472.           break;
  473.          case 1014:
  474.            if(CurrentVol>=2) CurrentVol-=2;
  475.            Global.SndVol=CurrentVol;
  476.            if((play)&&(Volume))
  477.              CallVolume();
  478.            ShowVolume();
  479.           break;
  480.         }
  481.        i=Received(Port);
  482.       }  
  483.     }
  484.   }
  485.  Stop();
  486.  CloseAll();
  487. }
  488.  
  489.  
  490. /* Installationsroutine */
  491. VOID OpenAll()
  492. {
  493.  REGISTER UWORD              i;
  494.  register struct MsgPort    *p;
  495.  register struct FileHandle *fh;
  496.  
  497.  ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
  498.  if(ATUtilitiesBase==NULL)
  499.   {
  500.    printf("FEHLER: Kann ATUtilities-Library nicht öffnen.\n");
  501.    CloseAll();
  502.   }
  503.  
  504.  p=FindPort(HiFiPort);
  505.  if(p!=NULL)
  506.   {
  507.    InfoRequest("ATUtilities HiFi-Player ist schon aktiv.");
  508.    CloseAll();
  509.   }
  510.  
  511.  if((SysBase->lib_Version<36)||(DOSBase->lib_Version<36))
  512.   {
  513.    InfoRequest("HiFi-Player benötigt Kickstart 2.0!");
  514.    CloseAll();
  515.   }
  516.  
  517.  Task=FindTask(NULL);
  518.  
  519.  GfxBase=OpenLibrary("graphics.library",0L);
  520.  IntuitionBase=OpenLibrary("intuition.library",0L);
  521.  if((GfxBase==NULL)||(IntuitionBase==NULL))
  522.   {
  523.    CloseAll();
  524.   }
  525.  
  526.  AslBase=OpenLibrary("asl.library",0L);
  527.  if(AslBase==NULL)
  528.   {
  529.    InfoRequest("Konnte Asl-Library nicht laden.");
  530.    CloseAll();
  531.   }
  532.  
  533.  GadToolsBase=OpenLibrary("gadtools.library",0L);
  534.  if(GadToolsBase==NULL)
  535.   {
  536.    InfoRequest("Konnte GadTools-Library nicht laden.");
  537.    CloseAll();
  538.   }
  539.  
  540.  UtilityBase=OpenLibrary("utility.library",0L);
  541.  if(UtilityBase==NULL)
  542.   {
  543.    InfoRequest("Konnte Utility-Library nicht laden.");
  544.    CloseAll();
  545.   }
  546.  
  547.  opal=GetOpalFont();
  548.  
  549.  Port=CreatePort(HiFiPort,0L);
  550.  if(Port==NULL)
  551.   {
  552.    ErrorRequest(ERROR_MPORT);
  553.    CloseAll();
  554.   }
  555.  
  556.  fh=Open(HiFiPrefsName,MODE_OLDFILE);
  557.  if(fh!=NULL)
  558.   {
  559.    Read(fh,&HiFiPrefs,sizeof(struct HiFiPrefs));
  560.    Close(fh);
  561.   }
  562.  
  563.  Catalog=AllocMem(CATSIZE*2,MEMF_CLEAR|MEMF_PUBLIC);
  564.  if(Catalog==NULL)
  565.   {
  566.    ErrorRequest(ERROR_ALLOC);
  567.    CloseAll();
  568.   }
  569.  Cat2=(ULONG)Catalog+(ULONG)CATSIZE;
  570.  
  571.  ReqTags=AllocateTagItems(8L);
  572.  if(ReqTags==NULL)
  573.   {
  574.    InfoRequest("Kein Speicher für Tag-Items!\n");
  575.    CloseAll();
  576.   }
  577.  
  578.  ReqTags[0].ti_Tag=ASL_Pattern;
  579.  
  580.  ReqTags[1].ti_Tag=ASL_FuncFlags;
  581.  ReqTags[1].ti_Data=FILF_MULTISELECT|FILF_PATGAD;
  582.  
  583.  ReqTags[2].ti_Tag=ASL_Hail;
  584.  ReqTags[2].ti_Data="HiFi-Player - Dateiauswahl";
  585.  
  586.  ReqTags[3].ti_Tag=ASL_Width;
  587.  ReqTags[3].ti_Data=500;
  588.  
  589.  ReqTags[4].ti_Tag=ASL_Height;
  590.  ReqTags[4].ti_Data=200;
  591.  
  592.  ReqTags[5].ti_Tag=ASL_TopEdge;
  593.  ReqTags[5].ti_Data=0;
  594.  
  595.  ReqTags[6].ti_Tag=ASL_LeftEdge;
  596.  ReqTags[6].ti_Data=80;
  597.  
  598.  ReqTags[7].ti_Tag=TAG_DONE;
  599.  
  600.  FileReq=AllocAslRequest(ASL_FileRequest,NULL);
  601.  if(FileReq==NULL)
  602.   {
  603.    InfoRequest("Kein Speicher für ASL-Requester!");
  604.    CloseAll();
  605.   }
  606.  
  607.  PortSignal=Port->mp_SigBit;
  608.  PortSignalMask=(1L<<PortSignal);
  609.  WaitSignalMask=PortSignalMask;
  610.  ChangeTaskPri(10);
  611.  
  612.  Global.AslBase=AslBase;
  613.  Global.DOSBase=DOSBase;
  614.  Global.IntuitionBase=IntuitionBase;
  615.  Global.GfxBase=GfxBase;
  616.  Global.GadToolsBase=GadToolsBase;
  617.  Global.SndNum=0;
  618.  Global.SndVol=HiFiPrefs.Volume;
  619.  CurrentVol=HiFiPrefs.Volume;
  620.  Global.SndLBal=HiFiPrefs.LBal;
  621.  Global.SndRBal=HiFiPrefs.RBal;
  622.  Global.LED=1;
  623.  Global.Timer=SysBase->VBlankFrequency;
  624.  Global.GetListData=(VOID *)xGetListData;
  625.  Global.LoadFile=(VOID *)xLoadFile;
  626.  Global.CopyDir=(VOID *)xCopyDir;
  627.  Global.CopyFile=(VOID *)xCopyFile;
  628.  Global.CopyString=(VOID *)xCopyString;
  629.  Global.AudioAlloc=(VOID *)xAudioAlloc;
  630.  Global.AudioFree=(VOID *)xAudioFree;
  631.  Global.StartInt=(VOID *)xStartInt;
  632.  Global.StopInt=(VOID *)xStopInt;
  633.  Global.SongEnd=(VOID *)xSongEnd;
  634.  Global.CutSuffix=(VOID *)xCutSuffix;
  635.  Global.SetTimer=(VOID *)xSetTimer;
  636.  MyInt.is_Node.ln_Succ=NULL;
  637.  MyInt.is_Node.ln_Pred=NULL;
  638.  MyInt.is_Node.ln_Pri=0;
  639.  MyInt.is_Node.ln_Type=NT_INTERRUPT;
  640.  MyInt.is_Node.ln_Name="hifiplayer-ghettoblaster.interrupt";
  641.  MyInt.is_Data=&Global;
  642.  LoadCatalog(&HiFiPrefs.DefaultCatalog);
  643. }
  644.  
  645.  
  646. /* Alle Player aus Liste laden */
  647. VOID LoadAllPlayers()
  648. {
  649.  REGISTER BOOL bool;
  650.  
  651.  if(ploaded==FALSE)
  652.   {
  653.    bool=LoadPlayer("AT:HiFi-System/Player/StarTrekker4AM");
  654.    if(bool==FALSE)
  655.     {
  656.      MultiRequest("Player \"StarTrekker4AM\" wird unbedingt zun Prog-",
  657.                   "rammstart benötigt, ist aber nicht vorhanden!",
  658.                   "Okay",0L);
  659.      CloseAll();
  660.     }
  661.    LoadPlayer("AT:HiFi-System/Player/IFF-SMUS");
  662.    LoadPlayer("AT:HiFi-System/Player/IFF-8SVX");
  663.    LoadPlayer("AT:HiFi-System/Player/MarkII");
  664.    LoadPlayer("AT:HiFi-System/Player/JamCracker");
  665.    LoadPlayer("AT:HiFi-System/Player/fc1.3");
  666.    LoadPlayer("AT:HiFi-System/Player/fc1.4");
  667.    LoadPlayer("AT:HiFi-System/Player/SaPlayer");
  668.    ploaded=TRUE;
  669.   }
  670. }
  671.  
  672.  
  673. /* Programmende */
  674. VOID CloseAll()
  675. {
  676.  UnLoadPlayers();
  677.  if(HCScreen!=NULL) HiFiControl();
  678.  if(Port) DeletePort(Port);
  679.  if(ReqTags) FreeTagItems(ReqTags);
  680.  if(FileReq) FreeAslRequest(FileReq);
  681.  if(Catalog) FreeMem(Catalog,CATSIZE*2);
  682.  if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
  683.  if(GfxBase) CloseLibrary(GfxBase);
  684.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  685.  if(UtilityBase) CloseLibrary(UtilityBase);
  686.  if(GadToolsBase) CloseLibrary(GadToolsBase);
  687.  if(AslBase) CloseLibrary(AslBase);
  688.  exit(0);
  689. }
  690.  
  691.  
  692. /* Katalog laden */
  693. VOID LoadCatalog(name)
  694.  UBYTE *name;
  695. {
  696.  UBYTE                       str[10];
  697.  REGISTER UWORD              i;
  698.  register struct FileHandle *fh;
  699.  
  700.  RndStart();
  701.  if(name==NULL)
  702.   {
  703.    ReqTags[0].ti_Data="#?.cat";
  704.    ReqTags[1].ti_Data=FILF_PATGAD;
  705.    if(AslRequest(FileReq,ReqTags))
  706.     {
  707.      strcpy(&dir,FileReq->rf_Dir);
  708.      i=strlen(&dir)-1;
  709.      if((dir[i]!=':')&&(dir[0]!=0x00)) { dir[i+1]='/'; dir[i+2]=0x00; }
  710.      strcat(&dir,FileReq->rf_File);
  711.      name=&dir;
  712.     } else name=NULL;
  713.   }
  714.  if(name!=NULL)
  715.   {
  716.    fh=Open(name,MODE_OLDFILE);
  717.    if(fh!=NULL)
  718.     {
  719.      Read(fh,&str,8);
  720.      if(!(strncmp(&str,"HIFI-CAT",8)))
  721.       {
  722.        for(i=0;i<MAXTITLES;i++)
  723.         {
  724.          Catalog->Title[i][0]=0x00;
  725.          PlayCount[i]=0;
  726.         }
  727.        Read(fh,Catalog,CATSIZE);
  728.       }
  729.      else InfoRequest("Datei ist kein Titelkatalog!");
  730.      Close(fh);
  731.     }
  732.    else
  733.     {
  734.      MultiRequest("Katalog konnte nicht geöffnet werden:",
  735.                   name,"Okay",NULL);
  736.     }
  737.   }
  738. }
  739.  
  740.  
  741. /* Katalog laden */
  742. VOID SaveCatalog()
  743. {
  744.  REGISTER UWORD              i;
  745.  register struct FileHandle *fh;
  746.  
  747.  ReqTags[0].ti_Data="#?.cat";
  748.  ReqTags[1].ti_Data=FILF_PATGAD|FILF_SAVE;
  749.  if(AslRequest(FileReq,ReqTags))
  750.   {
  751.    strcpy(&dir,FileReq->rf_Dir);
  752.    i=strlen(&dir)-1;
  753.    if((dir[i]!=':')&&(dir[0]!=0x00)) { dir[i+1]='/'; dir[i+2]=0x00; }
  754.    strcat(&dir,FileReq->rf_File);
  755.    fh=Open(&dir,MODE_NEWFILE);
  756.    if(fh!=NULL)
  757.     {
  758.      Write(fh,"HIFI-CAT",8);
  759.      Write(fh,Catalog,CATFILESIZE(Catalog->Entries));
  760.      Close(fh);
  761.     }
  762.    else
  763.     {
  764.      MultiRequest("Katalog konnte nicht erstellt werden:",
  765.                   &dir,"Okay",NULL);
  766.     }
  767.   }
  768. }
  769.  
  770.  
  771. /* Information */
  772. struct InfoItem ii1=
  773. {
  774.  0,0
  775. };
  776.  
  777. struct InfoItem ii2=
  778. {
  779.  1,1,
  780.  "Service",
  781.  "Haben Sie Anregungen oder",
  782.  "Verbesserungswünsche?",
  783.  "",
  784.  "Senden Sie eine PM (Persönliche Mitteilung)",
  785.  "an T.DREIBHOLZ in folgenden Mailboxen:",
  786.  "",
  787.  "Carrier: 02261/75835",
  788.  "Apogee: 02262/68614",
  789.  "",
  790.  "oder schreiben Sie an:",
  791.  "",
  792.  "Thomas Dreibholz",
  793.  "Molbachweg 7",
  794.  "D-51674 Wiehl"
  795. };
  796.  
  797. struct Info info=
  798. {
  799.  2,
  800.  &ii1,
  801.  &ii2
  802. };
  803.  
  804. VOID ShowInfo()
  805. {
  806.  ExtInformationBox(NULL,
  807.                    "ATUtilities HiFi-Player - Information",
  808.                    "$VER: HiFi-Player - Version 4.0",
  809.                    "Copyright (C) 1993-1994 by",
  810.                    "Thomas Dreibholz",
  811.                    "All rights reserved.",
  812.                    "AT:Icons/HiFi",&info);
  813. }
  814.  
  815.  
  816. /* Routinen zur Kommunikation mit den Player-Modulen */
  817. #asm
  818.    public _xGetListData
  819. _xGetListData:
  820.    move.l _mem,a0
  821.    move.l _size,d0
  822.    rts
  823.  
  824.    public _xAudioAlloc
  825. _xAudioAlloc:
  826.    clr.l d0
  827.    rts
  828.  
  829.    public _xLoadFile
  830. _xLoadFile:
  831.    clr.l d0
  832.    rts
  833.  
  834.    public _xAudioFree
  835. _xAudioFree:
  836.    rts
  837.  
  838.    public _xStartInt
  839. _xStartInt:
  840.    rts
  841.  
  842.    public _xStopInt
  843. _xStopInt:
  844.    rts
  845. #endasm
  846.  
  847. VOID xCopyDir()
  848. {
  849. }
  850.  
  851. VOID xCopyFile()
  852. {
  853. }
  854.  
  855. VOID xCopyString()
  856. {
  857. }
  858.  
  859. VOID xSetTimer()
  860. {
  861. }
  862.  
  863. VOID xCutSuffix()
  864. {
  865. }
  866.  
  867.  
  868. /* Songende erreicht */
  869. VOID xSongEnd()
  870. {
  871.  geta4();
  872.  Utility(HiFiPort,1505);
  873. }
  874.  
  875.  
  876. /* Assembler-Aufrufe für Player-Funktionen */
  877. #asm
  878.    public _CallInitPlayer
  879. _CallInitPlayer:
  880.    movem.l d1-d7/a0-a6,-(sp)
  881.    move.l #_Global,a5
  882.    move.l _InitPlayer,a0
  883.    jsr (a0)
  884.    movem.l (sp)+,d1-d7/a0-a6
  885.    rts
  886.  
  887.    public _CallEndPlayer
  888. _CallEndPlayer:
  889.    movem.l d1-d7/a0-a6,-(sp)
  890.    move.l #_Global,a5
  891.    move.l _EndPlayer,a0
  892.    jsr (a0)
  893.    movem.l (sp)+,d1-d7/a0-a6
  894.    rts
  895.  
  896.    public _CallStartInt
  897. _CallStartInt:
  898.    movem.l d1-d7/a0-a6,-(sp)
  899.    move.l #_Global,a5
  900.    move.l _StartInt,a0
  901.    jsr (a0)
  902.    movem.l (sp)+,d1-d7/a0-a6
  903.    rts
  904.  
  905.    public _CallStopInt
  906. _CallStopInt:
  907.    movem.l d1-d7/a0-a6,-(sp)
  908.    move.l #_Global,a5
  909.    move.l _StopInt,a0
  910.    jsr (a0)
  911.    movem.l (sp)+,d1-d7/a0-a6
  912.    rts
  913.  
  914.    public _CallInitSound
  915. _CallInitSound:
  916.    movem.l d1-d7/a0-a6,-(sp)
  917.    move.l #_Global,a5
  918.    move.l _InitSound,a0
  919.    jsr (a0)
  920.    movem.l (sp)+,d1-d7/a0-a6
  921.    rts
  922.  
  923.    public _CallEndSound
  924. _CallEndSound:
  925.    movem.l d1-d7/a0-a6,-(sp)
  926.    move.l #_Global,a5
  927.    move.l _EndSound,a0
  928.    jsr (a0)
  929.    movem.l (sp)+,d1-d7/a0-a6
  930.    rts
  931.  
  932.    public _CallVolume
  933. _CallVolume:
  934.    movem.l d1-d7/a0-a6,-(sp)
  935.    move.l #_Global,a5
  936.    move.l _Volume,a0
  937.    jsr (a0)
  938.    movem.l (sp)+,d1-d7/a0-a6
  939.    rts
  940.  
  941.    public _CallCheck1
  942. _CallCheck1:
  943.    movem.l d1-d7/a0-a6,-(sp)
  944.    move.l #_Global,a5
  945.    move.l _Check1,a0
  946.    jsr (a0)
  947.    movem.l (sp)+,d1-d7/a0-a6
  948.    rts
  949.  
  950.    public _CallCheck2
  951. _CallCheck2:
  952.    movem.l d1-d7/a0-a6,-(sp)
  953.    move.l #_Global,a5
  954.    move.l _Check2,a0
  955.    jsr (a0)
  956.    movem.l (sp)+,d1-d7/a0-a6
  957.    rts
  958.  
  959.    public _FilterOn
  960. _FilterOn:
  961.    bclr #1,$bfe001
  962.    rts
  963.  
  964.    public _FilterOff
  965. _FilterOff:
  966.    bset #1,$bfe001
  967.    rts
  968. #endasm
  969.  
  970.  
  971. /* Wiedergabe starten */
  972. BOOL Start(num)
  973.  UWORD num;
  974. {
  975.  LONG               i,j;
  976.  BOOL               okay,bool;
  977.  struct FileHandle *fh;
  978.  
  979.  
  980.  Global.AslBase=AslBase;
  981.  Global.DOSBase=DOSBase;
  982.  Global.IntuitionBase=IntuitionBase;
  983.  Global.GfxBase=GfxBase;
  984.  Global.GadToolsBase=GadToolsBase;
  985.  Global.SndNum=0;
  986.  Global.SndVol=HiFiPrefs.Volume;
  987.  CurrentVol=HiFiPrefs.Volume;
  988.  Global.SndLBal=HiFiPrefs.LBal;
  989.  Global.SndRBal=HiFiPrefs.RBal;
  990.  Global.LED=1;
  991.  Global.Timer=SysBase->VBlankFrequency;
  992.  Global.GetListData=(VOID *)xGetListData;
  993.  Global.LoadFile=(VOID *)xLoadFile;
  994.  Global.CopyDir=(VOID *)xCopyDir;
  995.  Global.CopyFile=(VOID *)xCopyFile;
  996.  Global.CopyString=(VOID *)xCopyString;
  997.  Global.AudioAlloc=(VOID *)xAudioAlloc;
  998.  Global.AudioFree=(VOID *)xAudioFree;
  999.  Global.StartInt=(VOID *)xStartInt;
  1000.  Global.StopInt=(VOID *)xStopInt;
  1001.  Global.SongEnd=(VOID *)xSongEnd;
  1002.  Global.CutSuffix=(VOID *)xCutSuffix;
  1003.  Global.SetTimer=(VOID *)xSetTimer;
  1004.  MyInt.is_Node.ln_Succ=NULL;
  1005.  MyInt.is_Node.ln_Pred=NULL;
  1006.  MyInt.is_Node.ln_Pri=0;
  1007.  MyInt.is_Node.ln_Type=NT_INTERRUPT;
  1008.  MyInt.is_Node.ln_Name="hifiplayer-ghettoblaster.interrupt";
  1009.  MyInt.is_Data=&Global;
  1010.  
  1011.  
  1012.  
  1013.  if(Catalog->Title[num][0]==0x00) return(FALSE);
  1014.  WaitSymbol();
  1015.  if(ploaded==FALSE) LoadAllPlayers();
  1016.  ShowSTitle();
  1017.  okay=FALSE;
  1018.  InitPlayer=0L;
  1019.  EndPlayer=0L;
  1020.  InitSound=0L;
  1021.  EndSound=0L;
  1022.  Interrupt=0L;
  1023.  StartInt=0L;
  1024.  StopInt=0L;
  1025.  Check1=0L;
  1026.  Check2=0L;
  1027.  Volume=0L;
  1028.  printf("START: %s\n",&Catalog->Title[num]);
  1029.  fh=Open(&Catalog->Title[num],MODE_OLDFILE);
  1030.  if(fh!=NULL)
  1031.   {
  1032.    Seek(fh,0,OFFSET_END);
  1033.    size=Seek(fh,0,OFFSET_BEGINNING);
  1034.    printf(" << ALLOC=%ld            %ld>>\n",size,AvailMem(MEMF_CHIP|MEMF_LARGEST)/1024);
  1035.    mem=AllocMem(size,MEMF_CHIP|MEMF_PUBLIC);
  1036.    if(mem!=NULL)
  1037.     {
  1038.      Read(fh,mem,size);
  1039.      Global.ChkData=mem;
  1040.      Global.ChkSize=size;
  1041.      Global.DirArrayPtr="DF2:";
  1042.      Global.FileArrayPtr="Strings.smus";
  1043.      Global.PathArrayPtr=&Catalog->Title[num];
  1044.      bool=CheckX();
  1045.      if(bool==FALSE)
  1046.       {
  1047.        for(j=0;j<PlayerCnt;j++)
  1048.         {
  1049.          Tags=Segmente[j]->TagArray;
  1050.          Check1=GetTagData(DPT_Check1,NULL,Tags);
  1051.          Check2=GetTagData(DPT_Check2,NULL,Tags);
  1052.          if(Check1!=NULL)
  1053.           {
  1054.            i=CallCheck1();
  1055.            if(i==0) { bool=TRUE; break; }
  1056.           }
  1057.          if(Check2!=NULL)
  1058.           {
  1059.            i=CallCheck2();
  1060.            if(i==0) { bool=TRUE; break; }
  1061.           }
  1062.          if((Check1==NULL)&&(Check2==NULL))
  1063.           { bool=TRUE; break; }
  1064.         }
  1065.        pname=GetTagData(DPT_PlayerName,"Unbekannt",Tags);
  1066.       }
  1067.      if(bool==TRUE)
  1068.       {
  1069.        ShowPlayer();
  1070.        InitPlayer=GetTagData(DPT_InitPlayer,NULL,Tags);
  1071.        EndPlayer=GetTagData(DPT_EndPlayer,NULL,Tags);
  1072.        InitSound=GetTagData(DPT_InitSound,NULL,Tags);
  1073.        EndSound=GetTagData(DPT_EndSound,NULL,Tags);
  1074.        Interrupt=GetTagData(DPT_Interrupt,NULL,Tags);
  1075.        StartInt=GetTagData(DPT_StartInt,NULL,Tags);
  1076.        StopInt=GetTagData(DPT_StopInt,NULL,Tags);
  1077.        Check1=GetTagData(DPT_Check1,NULL,Tags);
  1078.        Check2=GetTagData(DPT_Check2,NULL,Tags);
  1079.        Volume=GetTagData(DPT_Volume,NULL,Tags);
  1080.        i=0; if(InitPlayer) i=CallInitPlayer();
  1081.        if(i==0)
  1082.         {
  1083.          PlaySymbol();
  1084.          if((StartInt!=NULL)&&(StopInt!=NULL))
  1085.           {
  1086.            CallStartInt();
  1087.            okay=TRUE;
  1088.           }
  1089.          else if((InitSound!=NULL)&&(EndSound!=NULL)&&(Interrupt!=NULL))
  1090.           {
  1091.            MyInt.is_Code=Interrupt;
  1092.            CallInitSound();
  1093.            AddIntServer(5,&MyInt);
  1094.            okay=TRUE;
  1095.           }
  1096.          Global.SndVol=CurrentVol;
  1097.          if(Volume) CallVolume();
  1098.          PlayCount[current]=1;
  1099.         }
  1100.       }
  1101.     }
  1102.    else
  1103.     {
  1104.      printf("--- OUT OF MEMORY ---\n%ld Bytes required!\n",size);
  1105.     }
  1106.    Close(fh);
  1107.   }
  1108.  return(okay);
  1109. }
  1110.  
  1111.  
  1112. /* Wiedergabe beenden */
  1113. VOID Stop()
  1114. {
  1115.  StopSymbol();
  1116.  pname=NULL;
  1117.  ShowPlayer();
  1118.  if(mem!=NULL)
  1119.   {
  1120.    if((StartInt!=NULL)&&(StopInt!=NULL))
  1121.     {
  1122.      CallStopInt();
  1123.     }
  1124.    else if((InitSound!=NULL)&&(EndSound!=NULL)&&(Interrupt!=NULL))
  1125.     {
  1126.      RemIntServer(5,&MyInt);
  1127.      CallEndSound();
  1128.     }
  1129.    if(EndPlayer) CallEndPlayer();
  1130.    FilterOn();
  1131.    printf(" <<  FREE=%ld         %ld>>\n",size,AvailMem(MEMF_CHIP|MEMF_LARGEST)/1024);
  1132.    FreeMem(mem,size);
  1133.    mem=NULL;
  1134.   }
  1135. }
  1136.  
  1137.  
  1138. /* Player-Modul laden */
  1139. BOOL LoadPlayer(name)
  1140.  UBYTE *name;
  1141. {
  1142.  if(PlayerCnt<199)
  1143.  Player[PlayerCnt]=LoadSeg(name);
  1144.  if(Player[PlayerCnt]!=NULL)
  1145.   {
  1146.    Segmente[PlayerCnt]=BADDR(Player[PlayerCnt]);
  1147.    PlayerCnt++;
  1148.    return(TRUE);
  1149.   }
  1150.  else
  1151.   {
  1152.    printf("Player \"%s\" ist nicht vorhanden!!!\n",name);
  1153.   }
  1154.  return(FALSE);
  1155. }
  1156.  
  1157.  
  1158. /* Alle Module entfernen */
  1159. VOID UnLoadPlayers()
  1160. {
  1161.  REGISTER UWORD i;
  1162.  
  1163.  if(PlayerCnt>0)
  1164.   {
  1165.    for(i=0;i<PlayerCnt;i++)
  1166.     {
  1167.      UnLoadSeg(Player[i]);
  1168.     }
  1169.   }
  1170. }
  1171.  
  1172.  
  1173. /* Play-Symbol im Kontrolldisplay */
  1174. VOID PlaySymbol()
  1175. {
  1176.  if(HiFiPrefs.Filter!=0) FilterOn(); else FilterOff();
  1177.  if(HCScreen!=NULL)
  1178.   {
  1179.    DrawCNBorder(HCWindow,35,5,50,35);
  1180.    SetAPen(HCRPort,3);
  1181.    Move(HCRPort,40,12);
  1182.    Draw(HCRPort,40,32);
  1183.    Draw(HCRPort,80,22);
  1184.    Draw(HCRPort,40,12);
  1185.   }
  1186. }
  1187.  
  1188.  
  1189. /* Warte-Symbol im Kontrolldisplay */
  1190. VOID WaitSymbol()
  1191. {
  1192.  if(HCScreen!=NULL)
  1193.   {
  1194.    DrawCNBorder(HCWindow,35,5,50,35);
  1195.    SetAPen(HCRPort,3);
  1196.    Move(HCRPort,40,22);
  1197.    Draw(HCRPort,80,22);
  1198.   }
  1199. }
  1200.  
  1201.  
  1202. /* Stop-Symbol im Kontrolldisplay */
  1203. VOID StopSymbol()
  1204. {
  1205.  if(HCScreen!=NULL)
  1206.   {
  1207.    DrawCNBorder(HCWindow,35,5,50,35);
  1208.    SetAPen(HCRPort,3);
  1209.    Move(HCRPort,40,12);
  1210.    Draw(HCRPort,40,32);
  1211.    Draw(HCRPort,80,32);
  1212.    Draw(HCRPort,80,12);
  1213.    Draw(HCRPort,40,12);
  1214.   }
  1215. }
  1216.  
  1217.  
  1218. /* Titel im Kontrolldisplay */
  1219. VOID ShowSTitle()
  1220. {
  1221.  if(HCScreen!=NULL)
  1222.   {
  1223.    DrawCNBorder(HCWindow,90,5,520,16);
  1224.    SetAPen(HCRPort,3);
  1225.    WriteMText(HCRPort,100,16,520,&Catalog->Title[current]);
  1226.   }
  1227. }
  1228.  
  1229.  
  1230. /* Player im Kontrolldisplay */
  1231. VOID ShowPlayer()
  1232. {
  1233.  if(HCScreen!=NULL)
  1234.   {
  1235.    DrawCNBorder(HCWindow,90,24,520,16);
  1236.    if(pname!=NULL)
  1237.     {
  1238.      SetAPen(HCRPort,3);
  1239.      WriteMText(HCRPort,100,35,520,pname);
  1240.     }
  1241.   }
  1242. }
  1243.  
  1244.  
  1245. /* Lautstärke im Kontrolldisplay */
  1246. VOID ShowVolume()
  1247. {
  1248.  REGISTER UWORD v;
  1249.  
  1250.  if(HCScreen!=NULL)
  1251.   {
  1252.    SetAPen(HCRPort,0);
  1253.    RectFill(HCRPort,616,6,629,39);
  1254.    v=(CurrentVol*33)/64;
  1255.    SetAPen(HCRPort,3);
  1256.    RectFill(HCRPort,616,39-v,629,39);
  1257.   }
  1258. }
  1259.  
  1260.  
  1261. /* Display updaten */
  1262. VOID Update()
  1263. {
  1264.  
  1265.  if(HCScreen!=NULL)
  1266.   {
  1267.    ScreenToFront(HCScreen);
  1268.    ShowSTitle();
  1269.    ShowPlayer();
  1270.    RndStart();
  1271.   }
  1272. }
  1273.  
  1274.  
  1275. /* Kontrolldisplay */
  1276. VOID HiFiControl()
  1277. {
  1278.  if(HCScreen==NULL)
  1279.   {
  1280.    HCScreen=OpenScreen(&HCScreenDef);
  1281.    if(HCScreen!=NULL)
  1282.     {
  1283.      HCWindowDef.Screen=HCScreen;
  1284.      HCWindow=OpenWindow(&HCWindowDef);
  1285.      if(HCWindow!=NULL)
  1286.       {
  1287.        HCRPort=HCWindow->RPort;
  1288.        HCViewPort=ViewPortAddress(HCWindow);
  1289.        SetRGB4(HCViewPort,0,7,5,8);
  1290.        SetRGB4(HCViewPort,1,13,13,13);
  1291.        SetRGB4(HCViewPort,2,2,2,2);
  1292.        SetRGB4(HCViewPort,3,15,15,5);
  1293.        SetFont(HCRPort,opal);
  1294.        ShowSTitle();
  1295.        ShowPlayer();
  1296.        DrawCNBorder(HCWindow,615,5,15,35);
  1297.        if(play) PlaySymbol(); else StopSymbol();
  1298.        ShowVolume();
  1299.        return;
  1300.       }
  1301.     }
  1302.   }  
  1303.  if(HCWindow) CloseWindow(HCWindow);
  1304.  if(HCScreen) CloseScreen(HCScreen);
  1305.  HCScreen=NULL;
  1306. }
  1307.  
  1308.  
  1309. /* Ausgabe-Einstellungen */
  1310. BOOL AuPrefs()
  1311. {
  1312.  UBYTE                        *defCat,*pdir,*vol,*lbal,*rbal,str[10];
  1313.  REGISTER UWORD                i,j;
  1314.  REGISTER ULONG                Class;
  1315.  REGISTER BOOL                 bool,ende;
  1316.  register struct Window       *win;
  1317.  register struct RastPort     *rp;
  1318.  register struct IntuiMessage *msg;
  1319.  register struct Gadget       *gad;
  1320.  struct Gadget                *filter,*astart,*aswait,*hctrl;
  1321.  register struct FileHandle   *fh;
  1322.  
  1323.  bool=FALSE;
  1324.  win=CreateStdWindow("HiFi-Player - Ausgabe-Einstellungen",
  1325.                      75,75,450,138,
  1326.                      CLOSEWINDOW|GADGETUP,
  1327.                      ACTIVATE|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG);
  1328.  if(win!=NULL)
  1329.   {
  1330.    rp=win->RPort;
  1331.    SetFont(rp,opal);
  1332.    CreateBoolGadget(win,10,15,155,12,"Einstellungen Okay",1);
  1333.    CreateBoolGadget(win,170,15,155,12,"Programm beenden",2);
  1334.    CreateBoolGadget(win,335,15,50,12,"Info",3);
  1335.    CreateBoolGadget(win,390,15,50,12,"Hilfe",4);
  1336.    WriteText(rp,15,40,"Titel-Katalog bei Programmstart laden:");
  1337.    defCat=CreateStringGadget(win,10,44,430,12,&HiFiPrefs.DefaultCatalog,127,5);
  1338.    SelectStdFPen(rp);
  1339.    WriteText(rp,15,70,"Verzeichnis mit Player-Modulen:");
  1340.    pdir=CreateStringGadget(win,10,74,430,12,&HiFiPrefs.PlayerDir,127,5);
  1341.    if(HiFiPrefs.Filter!=0)
  1342.      filter=CreateSToggleGadget(win,10,90,150,12,"Audio-Filter",6);
  1343.    else
  1344.      filter=CreateNToggleGadget(win,310,90,130,12,"Audio-Filter",6);
  1345.    if(HiFiPrefs.AutoPlaying!=0)
  1346.      astart=CreateSToggleGadget(win,10,90,150,12,"Auto-Start",7);
  1347.    else
  1348.      astart=CreateNToggleGadget(win,10,90,150,12,"Auto-Start",7);
  1349.    if(HiFiPrefs.AutoPlayingWait!=0)
  1350.      aswait=CreateSToggleGadget(win,10,105,150,12,"60 Sek. warten",8);
  1351.    else
  1352.      aswait=CreateNToggleGadget(win,10,105,150,12,"60 Sek. warten",8);
  1353.    if(HiFiPrefs.Control!=0)
  1354.      hctrl=CreateSToggleGadget(win,175,90,130,12,"Kontrolldisplay",12);
  1355.    else
  1356.      hctrl=CreateNToggleGadget(win,175,90,130,12,"Kontrolldisplay",12);
  1357.    sprintf(&str,"%ld",HiFiPrefs.Volume);
  1358.    vol=CreateIntegerGadget(win,310,105,130,10,&str,3,10);
  1359.    WriteText(rp,180,113,"Lautstärke:");
  1360.    WriteText(rp,180,128,"Balance:");
  1361.    sprintf(&str,"%ld",HiFiPrefs.LBal);
  1362.    lbal=CreateIntegerGadget(win,310,121,60,10,&str,3,10);
  1363.    sprintf(&str,"%ld",HiFiPrefs.RBal);
  1364.    rbal=CreateIntegerGadget(win,380,121,60,10,&str,3,10);
  1365.    ende=FALSE;
  1366.    while(ende==FALSE)
  1367.     {
  1368.      WaitPort(win->UserPort);
  1369.      msg=GTGetIMsg(win->UserPort);
  1370.      Class=msg->Class;
  1371.      gad=msg->IAddress;
  1372.      GTReplyIMsg(msg);
  1373.      switch(Class)
  1374.       {
  1375.        case CLOSEWINDOW:
  1376.          ende=TRUE;
  1377.         break;
  1378.        case GADGETUP:
  1379.          switch(gad->GadgetID)
  1380.           {
  1381.            case 1:
  1382.              fh=Open(HiFiPrefsName,MODE_NEWFILE);
  1383.              if(fh!=NULL)
  1384.               {
  1385.                i=atol(vol);
  1386.                if(i>64) i=64;
  1387.                HiFiPrefs.Volume=i;
  1388.                i=atol(lbal);
  1389.                if(i>64) i=64;
  1390.                HiFiPrefs.LBal=i;
  1391.                i=atol(rbal);
  1392.                if(i>64) i=64;
  1393.                HiFiPrefs.RBal=i;
  1394.                if(hctrl->Flags & SELECTED) HiFiPrefs.Control=1; else HiFiPrefs.Control=0;
  1395.                if(filter->Flags & SELECTED) HiFiPrefs.Filter=1; else HiFiPrefs.Filter=0;
  1396.                if(astart->Flags & SELECTED) HiFiPrefs.AutoPlaying=1; else HiFiPrefs.AutoPlaying=0;
  1397.                if(aswait->Flags & SELECTED) HiFiPrefs.AutoPlayingWait=1; else HiFiPrefs.AutoPlayingWait=0;
  1398.                strcpy(&HiFiPrefs.DefaultCatalog,defCat);
  1399.                strcpy(&HiFiPrefs.PlayerDir,pdir);
  1400.                Write(fh,&HiFiPrefs,sizeof(struct HiFiPrefs));
  1401.                Close(fh);
  1402.               }
  1403.              ende=TRUE;
  1404.             break;
  1405.            case 2:
  1406.              ende=bool=TRUE;
  1407.             break;
  1408.            case 3:
  1409.              ShowInfo();
  1410.             break;
  1411.            case 4:
  1412.              Help(HelpName,0);
  1413.             break;
  1414.           }
  1415.         break;
  1416.       }
  1417.     }
  1418.    DeleteStdWindow(win);
  1419.   }
  1420.  return(bool);
  1421. }
  1422.  
  1423.  
  1424. /* Titeleditor */
  1425. VOID TitleEd()
  1426. {
  1427.  UBYTE                         show[10];
  1428.  UBYTE                         select[MAXTITLES];
  1429.  REGISTER UBYTE                StdPen;
  1430.  REGISTER UWORD                i,j,k;
  1431.  REGISTER ULONG                Class;
  1432.  REGISTER BOOL                 ende,bool;
  1433.  register struct Window       *win;
  1434.  register struct RastPort     *rp;
  1435.  register struct IntuiMessage *msg;
  1436.  register struct Gadget       *gad,*prop,*rnd;
  1437.  register struct PropInfo     *pi;
  1438.  
  1439.  win=CreateStdWindow("HiFi-Player - Titeleditor",
  1440.                      25,25,580,167,
  1441.                      CLOSEWINDOW|GADGETUP,
  1442.                      WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
  1443.  if(win!=NULL)
  1444.   {
  1445.    rp=win->RPort;
  1446.    SetFont(rp,GetOpalFont());
  1447.    CreateBoolGadget(win,10,15,165,12,"Einstellungen okay",1);
  1448.    CreateBoolGadget(win,210,15,150,12,"Titel hinzufügen",2);
  1449.    CreateBoolGadget(win,370,15,150,12,"Titel löschen",3);
  1450.    CreateBoolGadget(win,525,15,45,12,"Neu",9);
  1451.    if(Catalog->Random!=0)
  1452.      rnd=CreateSToggleGadget(win,10,150,560,12,"Titelwahl durch Zufallszahlen",7466);
  1453.    else
  1454.      rnd=CreateNToggleGadget(win,10,150,560,12,"Titelwahl durch Zufallszahlen",7466);
  1455.    if(Catalog->Entries<=10) j=1; else j=Catalog->Entries-10;
  1456.    prop=CreatePropGadget(win,545,30,25,115,0,0,0,65535/j,4);
  1457.    pi=prop->SpecialInfo;
  1458.    SelectStdFPen(rp);
  1459.    StdPen=rp->FgPen;
  1460.    for(i=0;i<Catalog->Entries;i++) select[i]=StdPen;
  1461.    for(   ;i<MAXTITLES;i++) select[i]=0;
  1462.    for(i=0;i<10;i++) show[i]=i;
  1463.    i=32; k=0;
  1464.    for(j=1000;j<1010;j++)
  1465.     {
  1466.      CreateMinGadget(win,11,i,528,12,j);
  1467.      WriteMText(rp,15,i+8,530,&Catalog->Title[k]);
  1468.      i+=11; k++;
  1469.     }
  1470.    DrawNBorder(win,10,30,530,115);
  1471.  
  1472.    k=0;
  1473.    ende=FALSE;
  1474.    while(ende==FALSE)
  1475.     {
  1476.      WaitPort(win->UserPort);
  1477.      msg=GTGetIMsg(win->UserPort);
  1478.      Class=msg->Class;
  1479.      gad=msg->IAddress;
  1480.      GTReplyIMsg(msg);
  1481.      switch(Class)
  1482.       {
  1483.        case CLOSEWINDOW:
  1484.          ende=TRUE;
  1485.         break;
  1486.        case GADGETUP:
  1487.          switch(gad->GadgetID)
  1488.           {
  1489.            case 1:
  1490.              ende=TRUE;
  1491.             break;
  1492.            case 2:
  1493.              ReqTags[0].ti_Data="#?";
  1494.              ReqTags[1].ti_Data=FILF_PATGAD|FILF_MULTISELECT;
  1495.              if((AslRequest(FileReq,ReqTags)))
  1496.               {
  1497.                j=FileReq->rf_NumArgs;
  1498.                if(j>0)
  1499.                 {
  1500.                  fargs=FileReq->rf_ArgList;
  1501.                  while(j--)
  1502.                   {
  1503.                    if(Catalog->Entries<MAXTITLES)
  1504.                     {
  1505.                      lock=fargs->wa_Lock;
  1506.                      NameFromLock(lock,&dir,80);
  1507.                      i=strlen(&dir)-1;
  1508.                      if(dir[i]!=':') { dir[i+1]='/'; dir[i+2]=0x00; }
  1509.                      strcpy(&Catalog->Title[Catalog->Entries],&dir);
  1510.                      strcat(&Catalog->Title[Catalog->Entries],fargs->wa_Name);
  1511.                      Catalog->Entries++;
  1512.                     } else DisplayBeep(NULL);
  1513.                    fargs++;
  1514.                   }
  1515.                  for(i=0;i<Catalog->Entries;i++) select[i]=StdPen;
  1516.                  for(   ;i<MAXTITLES;i++) select[i]=0;
  1517.                  for(i=0;i<10;i++) show[i]=i;
  1518.                  i=32;
  1519.                  DrawCNBorder(win,10,30,530,115);
  1520.                  for(k=0;k<10;k++)
  1521.                   {
  1522.                    if(k<Catalog->Entries)
  1523.                     {
  1524.                      WriteMText(rp,15,i+8,530,&Catalog->Title[k]);
  1525.                      i+=11;
  1526.                     } else break;
  1527.                   }
  1528.                  if(Catalog->Entries<=10) j=1; else j=Catalog->Entries-10;
  1529.                  ModifyProp(prop,win,NULL,
  1530.                             PROPBORDERLESS|FREEVERT|AUTOKNOB,
  1531.                             0,0,0,65535/j);
  1532.                 }
  1533.               }
  1534.             break;
  1535.            case 7466:
  1536.              if(rnd->Flags & SELECTED) Catalog->Random=1; else Catalog->Random=0;
  1537.             break;
  1538.            case 9:
  1539.              bool=MultiRequest("Wollen Sie wirklich einen neuen",
  1540.                                "Katalog erstellen?",
  1541.                                "Ja, Erstellen","Nein, Abbruch");
  1542.              if(bool==TRUE)
  1543.               {
  1544.                bool=MultiRequest("Wollen Sie eventuelle Änderungen im aktuellen",
  1545.                                  "Titelkatalog abspeichern oder verwerfen?",
  1546.                                  "Abspeichern","Verwerfen");
  1547.                if(bool==TRUE) SaveCatalog();
  1548.                k=0;
  1549.                DrawCNBorder(win,10,30,530,115);
  1550.                for(i=0;i<Catalog->Entries;i++) select[i]=StdPen;
  1551.                for(   ;i<MAXTITLES;i++) select[i]=0;
  1552.                for(i=0;i<10;i++) show[i]=i;
  1553.                for(i=0;i<MAXTITLES;i++) Catalog->Title[i][0]=0x00;
  1554.                Catalog->Entries=0;
  1555.                ModifyProp(prop,win,NULL,
  1556.                           PROPBORDERLESS|FREEVERT|AUTOKNOB,
  1557.                           0,0,0,65535);
  1558.               }
  1559.             break;
  1560.            case 3:
  1561.              bool=MultiRequest("Wollen Sie wirklich alle gewählten",
  1562.                                "Titel aus dem Katalog löschen?",
  1563.                                "Ja, Löschen","Nein, Abbruch");
  1564.              if(bool==TRUE)
  1565.               {
  1566.                j=0;
  1567.                for(i=0;i<Catalog->Entries;i++)
  1568.                 {
  1569.                  if(select[i]!=3)
  1570.                   {
  1571.                    strcpy(&Cat2->Title[j],&Catalog->Title[i]); j++;
  1572.                   }
  1573.                 }
  1574.                Cat2->Entries=j;
  1575.                for(   ;j<MAXTITLES;j++) Cat2->Title[j][0]=0x00;
  1576.                CopyMem(Cat2,Catalog,CATSIZE);
  1577.                DrawCNBorder(win,10,30,530,115);
  1578.                for(i=0;i<Catalog->Entries;i++) select[i]=StdPen;
  1579.                for(   ;i<MAXTITLES;i++) select[i]=0;
  1580.                for(i=0;i<10;i++) show[i]=i;
  1581.                i=32;
  1582.                for(k=0;k<10;k++)
  1583.                 {
  1584.                  if(k<Catalog->Entries)
  1585.                   {
  1586.                    WriteMText(rp,15,i+8,530,&Catalog->Title[k]);
  1587.                    i+=11;
  1588.                   } else break;
  1589.                 }
  1590.                if(Catalog->Entries<=10) j=1; else j=Catalog->Entries-10;
  1591.                ModifyProp(prop,win,NULL,
  1592.                           PROPBORDERLESS|FREEVERT|AUTOKNOB,
  1593.                           0,0,0,65535/j);
  1594.               }
  1595.             break;
  1596.            case 4:
  1597.              if(Catalog->Entries>10)
  1598.               {
  1599.                j=pi->VertPot/(65535/(Catalog->Entries-10));
  1600.                if(j!=k)
  1601.                 {
  1602.                  k=j;
  1603.                  DrawCNBorder(win,10,30,530,115);
  1604.                  for(i=0;i<10;i++)
  1605.                   {
  1606.                    show[i]=k+i;
  1607.                    SetAPen(rp,select[show[i]]);
  1608.                    WriteMText(rp,15,40+(i*11),530,&Catalog->Title[k+i]);
  1609.                   }
  1610.                 }
  1611.               }
  1612.             break;
  1613.            default:
  1614.              if((gad->GadgetID>=1000)&&(gad->GadgetID<1010))
  1615.               {
  1616.                j=gad->GadgetID-1000;
  1617.                if(select[show[j]]!=0)
  1618.                 {
  1619.                  if(select[show[j]]!=3)
  1620.                    select[show[j]]=3;
  1621.                  else
  1622.                    select[show[j]]=StdPen;
  1623.                  SetAPen(rp,select[show[j]]);
  1624.                  WriteMText(rp,15,40+(j*11),530,&Catalog->Title[show[j]]);
  1625.                 }
  1626.               }
  1627.             break;
  1628.           }
  1629.         break;
  1630.       }
  1631.     }
  1632.    DeleteStdWindow(win);
  1633.   }
  1634. }
  1635.  
  1636.  
  1637. /* Konvertierung zu StarTrekker4AM */
  1638. BOOL CheckX()
  1639. {
  1640.  
  1641.  Tags=Segmente[0]->TagArray;
  1642.  if(size>=0x43b)
  1643.   {
  1644.    if(mem[0x438]=='M')
  1645.      if(mem[0x439]=='.')
  1646.        if(mem[0x43a]=='K')
  1647.          if(mem[0x43b]=='.')
  1648.           {
  1649.            pname="Konvertierung von NoiseTracker zu StarTrekker4AM";
  1650.            return(TRUE);
  1651.           }
  1652.    if(mem[0x438]=='F')
  1653.      if(mem[0x439]=='L')
  1654.        if(mem[0x43a]=='T')
  1655.          if(mem[0x43b]=='4')
  1656.           {
  1657.            pname="Konvertierung von StarTrekker zu StarTrekker4AM";
  1658.            return(TRUE);
  1659.           }
  1660.   }
  1661.  return(FALSE);   
  1662. }
  1663.  
  1664.  
  1665. /* Zufallszahl ermitteln */
  1666. UWORD Zufall(max)
  1667.  UWORD max;
  1668. {
  1669.  REGISTER UWORD z;
  1670.  
  1671.  z=rand();
  1672.  return(z % max);
  1673. }
  1674.  
  1675.  
  1676. /* Startwert für Zufallszahlengenerator */
  1677. VOID RndStart()
  1678. {
  1679.  
  1680.  srand(RT() % 10);
  1681. }
  1682.  
  1683.  
  1684. /* Startwert holen */
  1685. #asm
  1686.    public _RT
  1687. _RT:
  1688.    move.w $dff006,d0
  1689.    ext.l d0
  1690.    rts
  1691. #endasm
  1692.  
  1693.